package codingPractice.xiaoHongShu;

import java.util.Arrays;
import java.util.Scanner;

/*
一组数，分成两组，求两组数和的 差的绝对值的最小值
 */

public class Test1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextInt()) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            for(int i=0;i<n;i++) {
                arr[i] = sc.nextInt();
            }
            int sum = Arrays.stream(arr).sum();
            int target = sum / 2;
            boolean[] dp = new boolean[target + 1];
            dp[0] = true;

            for(int num: arr) {
                for(int j=target; j >= num; j--) {
                    dp[j] = dp[j] || dp[j-num];
                }
            }

            int sum1 = 0;
            for(int i=target; i>=0; i--) {
                if(dp[i]) {
                    sum1 = i;
                    break;
                }
            }

            int sum2 = sum - sum1;
            int result = sum2 - sum1;
            System.out.println(result);
        }
    }
}
